package com.googlecode.xmlServerBackend.server;

// IO objects used in this servlet
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;


// Servlet objects used in this servlet
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public final class XMLServlet extends HttpServlet{
	/**
	 * Generated serial Version ID. 
	 */

	private static final long serialVersionUID = 510045970250283364L;

	private static final String MENU = "listofdocs.xml";
	private static final String DATA = "exampleData.xml";
	/**
	 * Runs the xml fetcher
	@param  request - HttpServletRequest
	@param response - HttpServletResponse
	*
	@throws ServletExceptionhttp://marketplace.eclipse.org/marketplace-client-intro?mpc_install=248
	@throws IOException
	 *  
	 */
	public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		
	// initialize the string that will be added to the response.
	//	String mResponse="<point1><value1>1</value1><value2>1</value2></point1>";
		FileInputStream fstream = null;
		if(request.getParameter("menu") != null){
			fstream = new FileInputStream(MENU);
		}else{
			fstream = new FileInputStream(DATA);
		}
		response.setCharacterEncoding("UTF-8");
	    response.setContentType("text/xml");	    
	    response.setStatus(200);
		PrintWriter out= response.getWriter();
		  
		  // Get the object of DataInputStream
		  DataInputStream in = new DataInputStream(fstream);
		  BufferedReader br = new BufferedReader(new InputStreamReader(in));
		  String strLine;
		  //Read File Line By Line
		  while ((strLine = br.readLine()) != null){
		  // Print the content on the console
		  out.println (strLine);
		  }
		  //Close the input stream
		  in.close();
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		doGet(request,response);
	}
	private String getMenu(){
		return null;
		
	}
	
	
}

/*
Intro
outline
summary
Sources*/